using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace NET.Library.Windows.Forms.DataControls.DataGridViews
{
    /// <summary>
    /// Populate variable types with values from DataGridView control data items.
    /// </summary>
    public class DataGridViewDataItems
    {
        /// <summary>
        /// Return DataGridView control data item as a string type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static string StringDataItem(string fieldName, DataGridViewRowEventArgs e)
        {
            return DataItem(fieldName, e).ToString();
        }

        public static string StringDataItem(string fieldName, DataGridViewCellEventArgs e, DataGridView dataGridView)
        {
            return DataItem(fieldName, e, dataGridView).ToString();
        }

        /// <summary>
        /// Return DataGridView control data item as a DateTime type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static DateTime DateTimeDataItem(string fieldName, DataGridViewRowEventArgs e)
        {
            return (DateTime)DataItem(fieldName, e);
        }

        public static DateTime DateTimeDataItem(string fieldName, DataGridViewCellEventArgs e, DataGridView dataGridView)
        {
            return (DateTime)DataItem(fieldName, e, dataGridView);
        }

        /// <summary>
        /// Return DataGridView control data item as an integer type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static int IntDataItem(string fieldName, DataGridViewRowEventArgs e)
        {
            return (int)DataItem(fieldName, e);
        }

        public static int IntDataItem(string fieldName, DataGridViewCellEventArgs e, DataGridView dataGridView)
        {
            return (int)DataItem(fieldName, e, dataGridView);
        }

        /// <summary>
        /// Return DataGridView control data item used as a Boolean type.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static bool BoolDataItem(string fieldName, DataGridViewRowEventArgs e)
        {
            return (bool)DataItem(fieldName, e);
        }

        public static bool BoolDataItem(string fieldName, DataGridViewCellEventArgs e, DataGridView dataGridView)
        {
            return (bool)DataItem(fieldName, e, dataGridView);
        }

        #region Private Methods
        private static object DataItem(string fieldName, DataGridViewRowEventArgs e)
        {
            return e.Row.Cells[fieldName].Value;
        }

        private static object DataItem(string fieldName, DataGridViewCellEventArgs e, DataGridView dataGridView)
        {
            return dataGridView.Rows[e.RowIndex].Cells[fieldName].Value;
        }
        #endregion
    }
}
